<!--  -->

<template>
  <div id="showpop">
    <div class="nav bg-theme color-f text-l">
      <div style="display:flex;flex:2;">
        <i class="iconfont icon-fanhui font19 pl08 iback" @click="gotoMobile()"></i>
        <!-- 详情进入 -->
        <span class="font19 ml16">
          {{ pagename }}
        </span>
      </div>

      <!-- 起草按钮 -->
      <span style="margin-right:10px;margin-left:10px">
        <van-icon @click='accountClick()' name="orders-o" size="25" />
      </span>
      <span style="margin-right:10px;margin-left:10px">
        <van-icon @click='drawupClick()' name="plus" size="25" />
      </span>
      <span style="margin-right:10px;margin-left:10px">
        <van-icon @click="searchDialog()" name="search" size="25" />
      </span>
    </div>


    <div class="pageview">
      <component :is="tabviewName" ref="searchdata" style="height:calc(100vh-50px)"></component>
      <van-popup v-model="showtodoDialog" position="top" style="padding:20px 0 20px 0" get-container="#showpop">
        <van-field input-align='left' label-width="2.5em" v-model="todoDialogTitle" label="标题:" placeholder="请填写标题" />
        <div style="display: flex;margin:20px 0 0 0">
          <div style="width:50% ;text-align: center;">
            <van-button style=" display: inline-block;margin:0 20px 0 20px;padding:0 36px 0 36px"
              @click="chongzhibutton" type="default">
              重置</van-button>
          </div>

          <div style="width:50%;text-align: center;">
            <van-button style=" display: inline-block;margin:0 20px 0 20px;padding:0 36px 0 36px" @click="cancelbutton"
              type="primary" color="#60a9ec">
              查询</van-button>
          </div>
        </div>

      </van-popup>

      <van-popup v-model="showCreatDialog" position="bottom" get-container="#showpop">
        <van-picker visible-item-count="4" show-toolbar :columns="drawTitleList" @confirm="creatDialogConfirm"
          @cancel="showCreatDialog = false" />
      </van-popup>
    </div>

  </div>
</template>

<script type="text/javascript">


import tabview0 from '@/components/xxzdtab0'
import jDrawupUtil from '@/assets/js/dict_process_helper';
import jAccountUtil from '@/assets/js/qyzx_helper';


import { mapGetters } from 'vuex'
import { Toast } from 'vant';



export default {

  data() {
    return {
      tabviewName: '',
      showtodoDialog: false,
      todoDialogTitle: '',
      pagename: '政企项目管理系统',

      // 起草
      drawTitleList: [],
      showCreatDialog: false,

      isDrawup: false,
    }
  },
  computed: {

  },
  //生命周期--创建完成
  created() {

  },
  components: {
    tabview0,
  },
  //生命周期--挂载完成
  mounted() {
    if (window.history && window.history.pushState) {
      console.log('注册物理返回键');
      history.pushState(null, null, document.URL);
      window.addEventListener('popstate', this.gotoMobile, false);//false阻止默认事件
    }
    localStorage.setItem('dicttabNumber', 0)
    this.tabviewName = 'tabview0'
    this.pagename = '政企项目管理系统'
  },
  //方法调用
  methods: {

    searchDialog() {
      this.showtodoDialog = true;
    },
    chongzhibutton() {
      this.showtodoDialog = false;
      this.todoDialogTitle = '';
      this.$refs.searchdata.setsearchdata(this.todoDialogTitle)
    },
    cancelbutton() {
      this.showtodoDialog = false;
      this.$refs.searchdata.setsearchdata(this.todoDialogTitle)
    },
    gotoMobile() {
      this.addlistener();
      console.log('gotoMobile')
      if (this.showtodoDialog) {
        this.showtodoDialog = false;
      } else {
        localStorage.setItem('dicttabNumber', 0)
        console.log('main点击物理返回键222'),
          this.moaBridge_ha_djfupt.closeDoc({ refresh: false, appcode: 'djfupt' });
      }
    },
    addlistener() {
      if (window.history && window.history.pushState) {
        console.log('再次注册物理返回键监听');
        history.pushState(null, null, document.URL);
        window.addEventListener('popstate', this.gotoMobile, false);//false阻止默认事件
      }
    },

    // 企业致信 按钮
    accountClick() {

      this.drawTitleList = jAccountUtil.currentAccountNameList();
      this.showCreatDialog = true
      this.isDrawup = false
    },


    // 起草按钮
    drawupClick() {

      this.drawTitleList = jDrawupUtil.currentUserCanDrawupProcessNames();
      this.showCreatDialog = true
      this.isDrawup = true
    },

    // 起草 选中流程，跳转对应界面，开始起草
    creatDialogConfirm(value, index) {

      if (this.isDrawup) {

        this.drawupConfirm(value);
      }
      else {
        this.searchConfirm(index);
      }

    },

    // 企业致信 搜索
    searchConfirm(index) {

      let dict = jAccountUtil.getAccountWithIndex(index);
      this.$router.push(
        {
          name: 'qyzx_search',
          query: dict,
          params: {
            title: dict.value,
          }
        }
      )
    },

    // 
    drawupConfirm(value) {

      if (value == '应标支撑') {
        this.$router.push(
          {
            name: 'xbdetail',
            query: {
              location: 'dict.start',
              isdraw: '1',
              pmInsType: 'XB'
            }
          }
        )
      } else if (value == '方案支撑') {
        this.$router.push(
          {
            name: 'xcdetail',
            query: {
              location: 'dict.start',
              isdraw: '1',
              pmInsType: 'XC'
            }
          }
        )
      }
      else if (value == '项目进度' || value == '项目开工' || value == '项目交接' || value == '售前拜访' || value == '商机维护'
          || value == '三化预算填报') {

        console.log(jDrawupUtil.getPushTransitionTableParam(value));
        /// 去往 中转 商机列表
        this.$router.push(
          {
            name: 'drawup_transition_tab',
            query: jDrawupUtil.getPushTransitionTableParam(value)
          }
        )
      } else if (value == 'CA借用' || value == 'CA归还') {
        let isBorrow = value == 'CA借用'
        this.$router.push(
          {
            name: isBorrow ? 'xsdetail' : 'xtdetail',
            query: {
              pmInsType: isBorrow ? 'XS' : 'XT',
              location: 'dict.start',
              todoType: '1',
              isdraw: '1',
            }
          }
        )
      } else if (value == '项目变更') {

        console.log('项目变更 流转参数', jDrawupUtil.getPushTransitionTableParam(value));
        /// 去往 项目变更详情
        this.$router.push(
          {
            name: 'apcdetail',
            query: jDrawupUtil.getPushTransitionTableParam(value)
          }
        )
      }
      else if (value == '商机转项目') {

        /// 去往 项目变更详情
        this.$router.push(
          {
            name: 'sjzxm',
            query: jDrawupUtil.getPushTransitionTableParam(value)
          }
        )
      }
      else if (value == '5G项目管理') {

        /// 去往 5G项目管理 的
        this.$router.push(
          {
            name: 'sjzxm',
            query: jDrawupUtil.getPushTransitionTableParam(value)
          }
        )
      }
      else if (value == '商机研判') {
        /// 去往 商机研判 的
        this.$router.push(
            {
              name: 'drawup_transition_tab',
              query: jDrawupUtil.getPushTransitionTableParam(value)
            }
        )
      }



    },
  },





  destroyed() {
    window.removeEventListener('popstate', this.gotoMobile, false);//false阻止默认事件
  },
}
</script>

<style scoped>
/* @import url();*/
.item {
  text-align: center;
  width: 20%
}

.pageview {
  height: 100%;
  padding-top: 50px;
  margin-bottom: 60px;
  font-size: 12px;
}

.tabview {
  position: fixed;
  bottom: 0;
  width: 100%;
  line-height: var(--footer-height);
  background-color: gray;
  padding-top: 20px;
  padding-bottom: 20px;
}

.vh100 {
  width: 100%;
}

.pf-20 {
  padding-right: 20px;
}
</style>